import random, json, hashlib


def generate_rules(version, max_version, min_version):
    """
    Generates a random rules.
    """
    platform = random.choice(["IOS", "Android"])
    suffix = ".apk" if platform == "Android" else ".ipa"
    channel = "AppStore" if platform == "IOS" else "GooglePlay"
    cpu_arch = random.choice(["x86", "x64"])
    device_id_list = random.sample(range(1, 500000), 10)
    aid = f"my_update_app_{version}_{platform}_{channel}_{cpu_arch}"
    download_url = f"https://example.com/my_update_app_{version}_{platform}_{channel}_{cpu_arch}{suffix}"
    md5 = hashlib.md5(download_url.encode()).hexdigest()
    res = {
        "aid": aid,
        "platform": platform,
        "download_url": download_url,
        "update_version_code": version,
        "md5": md5,
        "device_id_list": device_id_list,
        "max_update_version_code": max_version,
        "min_update_version_code": min_version,
        "max_os_api": 16,
        "min_os_api": 13,
        "cpu_arch": cpu_arch,
        "channel": channel,
        "title": "测试标题",
        "update_tips": f'您正在尝试升级到{aid}版本！'
    }
    return res


# d = generate_rules("1.1", "1.0", "0.9")
# print(d)
